#include <linux/version.h>
#include_next <drm/display/drm_dp.h>

#ifndef _BACKPORT_DRM_DISPLAY_DRM_DP_H
#define _BACKPORT_DRM_DISPLAY_DRM_DP_H

#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 9, 0)
# define DP_TUNNELING_IRQ                    (1 << 5)

/* DP-tunneling */
#define DP_TUNNELING_OUI				0xe0000
#define  DP_TUNNELING_OUI_BYTES				3
#define DP_TUNNELING_DEV_ID				0xe0003
#define  DP_TUNNELING_DEV_ID_BYTES			6
#define DP_TUNNELING_HW_REV				0xe0009
#define  DP_TUNNELING_HW_REV_MAJOR_SHIFT		4
#define  DP_TUNNELING_HW_REV_MAJOR_MASK			(0xf << DP_TUNNELING_HW_REV_MAJOR_SHIFT)
#define  DP_TUNNELING_HW_REV_MINOR_SHIFT		0
#define  DP_TUNNELING_HW_REV_MINOR_MASK			(0xf << DP_TUNNELING_HW_REV_MINOR_SHIFT)
#define DP_TUNNELING_SW_REV_MAJOR			0xe000a
#define DP_TUNNELING_SW_REV_MINOR			0xe000b
#define DP_TUNNELING_CAPABILITIES			0xe000d
#define  DP_IN_BW_ALLOCATION_MODE_SUPPORT		(1 << 7)
#define  DP_PANEL_REPLAY_OPTIMIZATION_SUPPORT		(1 << 6)
#define  DP_TUNNELING_SUPPORT				(1 << 0)
#define DP_IN_ADAPTER_INFO				0xe000e
#define  DP_IN_ADAPTER_NUMBER_BITS			7
#define  DP_IN_ADAPTER_NUMBER_MASK			((1 << DP_IN_ADAPTER_NUMBER_BITS) - 1)
#define DP_USB4_DRIVER_ID				0xe000f
#define  DP_USB4_DRIVER_ID_BITS				4
#define  DP_USB4_DRIVER_ID_MASK				((1 << DP_USB4_DRIVER_ID_BITS) - 1)
#define DP_USB4_DRIVER_BW_CAPABILITY			0xe0020
#define  DP_USB4_DRIVER_BW_ALLOCATION_MODE_SUPPORT	(1 << 7)
#define DP_IN_ADAPTER_TUNNEL_INFORMATION		0xe0021
#define  DP_GROUP_ID_BITS				3
#define  DP_GROUP_ID_MASK				((1 << DP_GROUP_ID_BITS) - 1)
#define DP_BW_GRANULARITY				0xe0022
#define  DP_BW_GRANULARITY_MASK				0x3
#define DP_ESTIMATED_BW					0xe0023
#define DP_ALLOCATED_BW					0xe0024
#define DP_TUNNELING_STATUS				0xe0025
#define  DP_BW_ALLOCATION_CAPABILITY_CHANGED		(1 << 3)
#define  DP_ESTIMATED_BW_CHANGED			(1 << 2)
#define  DP_BW_REQUEST_SUCCEEDED			(1 << 1)
#define  DP_BW_REQUEST_FAILED				(1 << 0)
#define DP_TUNNELING_MAX_LINK_RATE			0xe0028
#define DP_TUNNELING_MAX_LANE_COUNT			0xe0029
#define  DP_TUNNELING_MAX_LANE_COUNT_MASK		0x1f
#define DP_DPTX_BW_ALLOCATION_MODE_CONTROL		0xe0030
#define  DP_DISPLAY_DRIVER_BW_ALLOCATION_MODE_ENABLE	(1 << 7)
#define  DP_UNMASK_BW_ALLOCATION_IRQ			(1 << 6)
#define DP_REQUEST_BW					0xe0031
#define  MAX_DP_REQUEST_BW				255
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 10, 0)
# define DP_ADAPTIVE_SYNC_SDP_OPERATION_MODE		GENMASK(1, 0)
# define DP_ADAPTIVE_SYNC_SDP_LENGTH				GENMASK(5, 0)

#define DP_SDP_ADAPTIVE_SYNC		0x22 /* DP 1.4 */

enum operation_mode {
	DP_AS_SDP_AVT_DYNAMIC_VTOTAL = 0x00,
	DP_AS_SDP_AVT_FIXED_VTOTAL = 0x01,
	DP_AS_SDP_FAVT_TRR_NOT_REACHED = 0x02,
	DP_AS_SDP_FAVT_TRR_REACHED = 0x03
};
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0)
#define DP_ALPM_PM_STATE_2A_SUPPORT	    (1 << 1) /* eDP 1.5 */
#define DP_ALPM_AUX_LESS_CAP		    (1 << 2) /* eDP 1.5 */

# define DP_PANEL_REPLAY_EARLY_TRANSPORT_SUPPORT	(1 << 2) /* eDP 1.5 */
# define DP_PANEL_REPLAY_VSC_SDP_CRC_EN                 (1 << 1) /* eDP 1.5 */
#define PANEL_REPLAY_CONFIG2                                     0x1b1 /* eDP 1.5 */
# define DP_PANEL_REPLAY_SINK_REFRESH_RATE_UNLOCK_GRANTED	 (1 << 0)
# define DP_PANEL_REPLAY_CRC_VERIFICATION			 (1 << 1)
# define DP_PANEL_REPLAY_SU_Y_GRANULARITY_EXTENDED_EN		 (1 << 2)
# define DP_PANEL_REPLAY_SU_Y_GRANULARITY_EXTENDED_VAL_SEL_SHIFT 3
# define DP_PANEL_REPLAY_SU_Y_GRANULARITY_EXTENDED_VAL_SEL_MASK  (0xf << 3)
# define DP_PANEL_REPLAY_SU_REGION_SCANLINE_CAPTURE		 (1 << 7)

#define DP_PANEL_PANEL_REPLAY_CAPABILITY		0xb1
# define DP_PANEL_PANEL_REPLAY_SU_GRANULARITY_REQUIRED	(1 << 5)
#define DP_PANEL_PANEL_REPLAY_X_GRANULARITY		0xb2
#define DP_PANEL_PANEL_REPLAY_Y_GRANULARITY		0xb4

# define DP_PANEL_REPLAY_ENABLE_SU_REGION_ET            (1 << 7) /* DP 2.1 */

# define DP_ALPM_PM_STATE_2A_SUPPORT	    (1 << 1) /* eDP 1.5 */
# define DP_ALPM_AUX_LESS_CAP		    (1 << 2) /* eDP 1.5 */

# define DP_ALPM_MODE_AUX_LESS		    (1 << 2) /* eDP 1.5 */
#endif

#endif